package com.charley.icloud.monitor;

import com.charley.icloud.common.port.PortApplicationEnvironmentPreparedEventListener;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@EnableAdminServer
@EnableDiscoveryClient // 开启Consul服务发现支持
@SpringBootApplication
public class MonitorMainAppStarter {

    public static void main(String[] args) throws UnknownHostException {
        Logger logger = LoggerFactory.getLogger(MonitorMainAppStarter.class);

        ApplicationContext applicationContext = SpringApplication.run(MonitorMainAppStarter.class,args);

        Environment environment = applicationContext.getEnvironment();
        String ipAddr = InetAddress.getLocalHost().getHostAddress();
        String port = environment.getProperty("server.port");
        String path = environment.getProperty("server.servlet.context-path");
        String appName = environment.getProperty("spring.application.name");

        if(path == null) path="";
        logger.info("\n---------------------------------------------------------------------------------------\n" +
                "Application '{}' is running! Access URLs:\t\n" +
                "Local: \t\thttp://localhost:" + port + path + "/\n" +
                "External: \thttp://" + ipAddr + ":" + port + path + "/\n" +
                "Consul: \thttp://localhost:8500/\n" +
                "------------------------------ 启动成功 By charley -------------------------------------\n", appName);
    }
}
